﻿(function (_this) {
    _this.Cookie = function (options) {
        var __this = new Object();
        function getConfig() {
            return {
                name: "",
                value: {},
                expires: 3600 * 24 * 30,
                path: "/",
                raw: true,
                domain: null,
                secure: null
            };
        }
        function init(options) {
            var _config = getConfig();
            var _config = $.extend(true, _config, options);
            if (String(_config.value) !== "[object Object]") {
                if (_config.value === null || _config.value === undefined) {
                    _config.expires = -1
                }
                if (typeof _config.expires === "number") {
                    var a = _config.expires,
                    f = _config.expires = new Date();
                    f.setDate(f.getDate() + a)
                }
                _config.value = String(_config.value);
                return (document.cookie = [
                    encodeURIComponent(_config.name), "=",
                    _config.raw ? _config.value : encodeURIComponent(_config.value),
                    _config.expires ? "; expires=" + _config.expires.toUTCString() : "",
                    _config.path ? "; path=" + _config.path : "",
                    _config.domain ? "; domain=" + _config.domain : "",
                    _config.secure ? "; secure" : ""
                ].join(""))
            }

            var e, b = _config.raw ?
            function (h) {
                return h
            } : decodeURIComponent;
            return (e = new RegExp("(?:^|; )" + encodeURIComponent(_config.name) + "=([^;]*)").exec(document.cookie)) ? b(e[1]) : null
        };
        return init(options);
    };


    _this.GetCookie = function (name) {
        var arr, reg = new RegExp("(^| )" + name + "=([^;]*)(;|$)");
        if (arr = document.cookie.match(reg))
            return arr[2];
        else
            return null;
    };

})(vui);
